
import { defineStore } from "pinia";
import {SurfaceSettingModel} from "@/store/model/SurfaceSettingModel";
import {post, Response} from "@/api/http";
import {saveSurfaceSetting} from "@/api/url";

const UseSurfaceSettingStore = defineStore("surfaceSetting", {
    state() {
        const surfaceSetting = SurfaceSettingModel.getNewSurfaceSetting();
        return {
            surfaceSetting: surfaceSetting,
        };
    },
    actions: {
        addIdToArray:function (id:number|null|undefined,ids:Array<number|null|undefined>){
            ids.splice(0);
            //console.log(ids)
            ids.push(id)
        },
        setSurfaceSetting: function (surfaceSetting: SurfaceSettingModel) {
            // console.log("surfaceSetting", surfaceSetting);
            // console.log('surfaceSetting',...surfaceSetting)
            this.surfaceSetting.setInfo({...surfaceSetting});
            // this.surfaceSetting.setInfo(...surfaceSetting);
            // this.setting = setting;
        },
        getSurfaceSetting: function (): SurfaceSettingModel {
            return this.surfaceSetting;
        },
        saveSurfaceSetting: async function (token:any){
            console.log("更新SurfaceSetting",this.getSurfaceSetting())
            try {
                const {data}: Response = await post({
                    url: saveSurfaceSetting,
                    data: this.getSurfaceSetting(),
                    token:token
                });
            }catch(e) {
                console.log(e)
                // message.error((e as Error).message)
            }
        }
    },
    getters: {},
});
export default UseSurfaceSettingStore;
